import Vue from 'vue'

//去空格
Vue.prototype.trimStr = function (str){
    return str.replace(/(^\s*)|(\s*$)/g,"")
};

//检查token
Vue.prototype.vCheck = function (){
      let token=''
      let login=''
      let name = "bedtoken" + "=";
      let ca = document.cookie.split(';');
      for (let i = 0; i < ca.length; i++) {
          let c = ca[i].split("=");
          if(this.trimStr(c[0])=="bedtoken"){
              token=c[1];
          }
      };
      if(token!=''){
        var miwen = '';
        var arr = token.split("/");
        for(var i in arr){
          miwen += String.fromCharCode(arr[i]/3);
        }
        this.$store.dispatch("tokensync",miwen);
        return true
      }else{
        return false
      };
};


//检查用户登录
Vue.prototype.vLogin = function (){
      let login='';
      let name = "bedLogin" + "=";
      let ca = document.cookie.split(';');
      for (let i = 0; i < ca.length; i++) {
          let c = ca[i].split("=");
          if(this.trimStr(c[0])=="bedLogin"){
              login=c[1];
          }
      };
      if(login!=''){
        //用户已登录
        var miwen = '';
        var arr = login.split("/");
        for(var i in arr){
          miwen += String.fromCharCode(arr[i]/3);
        }
        this.$store.dispatch("loginsync",miwen);
        return true
      }else{
        //this.$store.dispatch("loginBox");
        return false
      };
};